
BACKUP   := *~
# you can change the exe_name according to your will
EXE_NAME := sonicomSecureClient

RM       := rm -rf
CD 	     := cd
PWD      := pwd
PYTHON   := python
MKDIR    := mkdir -p
# static complie
#CC       := gcc -g -Wall -static
#dynamic complie
CC       := gcc -g -Wall

TRUE	 := true
FALSE	 := false

# relative libraries
#CFLAGS   := -L/usr/lib/x86_64-linux-gnu/ -lssl -lcrypto -lpthread
#CFLAGS   := -L/usr/lib/x86_64-linux-gnu/ -lssl -lcrypto -lsqlite3 -lpthread -ldl -lz
CFLAGS   := -Wl,-rpath=./libs -L/usr/lib/x86_64-linux-gnu/ -lssl -lcrypto -lpthread

HELP_MSG := "help about makefile\n" \
            "env     : generate prerequisite file or directory.\n" \
            "debug   : make the target file debug model.\n" \
            "release : make the target file release model.\n" \
            "clean   : remove all object and backup files.\n" \
            "help    : help about makefile.\n" \
            "without any parameter is to make the default goal!"


ifeq ($(notdir $(shell $(PWD))), python)
	PYTHON_CWD := .
else
	PYTHON_CWD := /usr/bin/python
endif


OBJ := main.o
OBJ += main_bean.o
OBJ += clientconfig.o
OBJ += config-util.o
OBJ += x509-util.o
OBJ += backwork.o
OBJ += socket-util.o
OBJ += log-util.o
OBJ += locker.o
OBJ += common.o



# this function used to show relative message
define show-message
	@echo $1
endef

define debug_model
	@cd $(PYTHON_CWD); \
	python vpnserver.debug.py
endef

define release_model
	@cd $(PYTHON_CWD); \
	python vpnserver.release.py
endef

define prepare_env

endef

$(EXE_NAME):$(OBJ)
	$(CC) -o $@ $^ $(CFLAGS)
	$(RM) $(OBJ) $(BACKUP)
	$(call show-message, ======================BUILD OVER======================)

.PHONY:env
env:
	$(call prepare_env)

.PHONY:debug
debug:
	$(call debug_model)

.PHONY:release
release:
	$(call release_model)

.PHONY:clean
clean:
	$(RM) $(OBJ) $(BACKUP) $(EXE_NAME)
	$(call show-message, ======================CLEAN OVER======================)

.PHONY:help
help:
	$(call show-message, $(HELP_MSG))









